﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Sparkle.Hosting;
using Sparkle.Wpf.Demo.UI.Attributes;

namespace Sparkle.Wpf.Demo.UI
{
    /// <summary>
    /// Interaction logic for ReportLink.xaml
    /// </summary>
    public partial class ReportLink : UserControl,ILinkPanel
    {
        RoutedEventHandler onLinkClickEvent = null;

        public ReportLink()
        {
            InitializeComponent();
            this.onLinkClickEvent += new RoutedEventHandler(LinkButton_Click);
        }

        public void LinkButton_Click(object sender, RoutedEventArgs e)
        {
            if (OnLinkClick != null)
            {
                OnLinkClick(sender, (sender is HyperlinkButton) ? (sender as HyperlinkButton).Tag : null);
            }
        }

        #region ILinkPanel Members

        public string Title { get { return this.txtTitle.Text; } set { this.txtTitle.Text = value; } }
        
        public UIElementCollection Links { get { return stkLinks.Children; } }

        public Type LinkType {get; set; }

        public void PanelChanged(UserControl newObject)
        {
            if (newObject == null) return;

            if (OnControlChange != null)
            {
                OnControlChange((newObject as UserControl), (newObject as UserControl).DataContext);
            }

            LinkPanel.ExtractLinks<ReportAttribute>(newObject, this.Links, onLinkClickEvent);
        }

        public event LinkHandler OnLinkClick;

        public event LinkHandler OnControlChange;

        #endregion
    }
}
